package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.SysHz;
import com.jy.wms.pojo.WmsReceiptTaskPda;
import com.jy.wms.pojo.WmsReceiptTaskPdaDetailed;
import com.jy.wms.service.WmsReceiptTaskPdaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: WmsReceiptTaskPdaController
 * @Description: TODO(PDA收货任务)
 * @Author Liyi
 * @Date Thu Nov 30 10:04:14 CST 2017
 */

@Controller
@RequestMapping("/wmsReceiptTaskPda")
@Api(value = "/wmsReceiptTaskPda", description = "PDA收货任务")
public class  WmsReceiptTaskPdaController extends BaseController<WmsReceiptTaskPdaService,WmsReceiptTaskPda> {

    @PostMapping(value = "/save")
    @ApiOperation(value = "生成PDA收货任务",response = JSONObject.class, notes = "POST新增生成收货任务")
    public @ResponseBody JSONObject save(@RequestBody Map<String,Object> map, HttpSession session) {
        try {
            List<SysHz> hz=(List<SysHz>)session.getAttribute(BaseSessionInfo.SessionConsignor);
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            baseService.baseInsert(map,userinfo,hz);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"生成PDA收货任务成功","", "");
        } catch (SucessException e){
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"生成PDA收货任务成功",e.getMessage(), "");
        } catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"生成PDA收货任务失败",e.getMessage(),"");
        }catch (RuntimeException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"生成PDA收货任务失败",e.getMessage(),"");
        }
    }

    @GetMapping(value = "/getPdaDetailed/{yqid}")
    @ApiOperation(value = "生成PDA收货任务",response = JSONObject.class, notes = "查看PDA收货任务明细")
    public @ResponseBody JSONObject getPdaDetailed(@PathVariable("yqid") String yqid, HttpSession session) {
        JSONObject json = getJSONObject();
        try {
            List<WmsReceiptTaskPdaDetailed> list = baseService.getPdaDetailed(yqid);
            json = SetStatus.setSearchType(JSONArray.fromObject(list).toString(),(int) list.size());
            return json;
        } catch (ServiceException e) {
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"查看PDA收货任务明细失败",e.getMessage(),"");
        }
    }
}
